<?php
//------------------------------------------------------------------------------
// File               : V_HotroEdit
// Modification       :
//------------------------------------------------------------------------------
// Date(yyyy.mm.dd)   Developer                       Action
//------------------------------------------------------------------------------
// 2007.03.09         Oanhhtk                         Created
//------------------------------------------------------------------------------
?>
<?php
include("../fckeditor/fckeditor.php") ;

function V_QuangcaoEdit(&$arrayData,$mode){
	global $arrayError,$db;
	$fqa=CM_getParameter("fqa");
	$ulr = "?".MODUL."=quangcao&fqa=".$fqa."&".ACTION."=".$mode;//htmlspecialchars($_SERVER['QUERY_STRING']);
	
	$strButtonLabel ="Ghi lại";
	$strLabel ="Sửa thông tin quảng cáo";
   
	if ($mode == "Add"){
		$strButtonLabel ="Thêm mới";	
		$strLabel ="Thêm mới thông tin quảng cáo";
	}	
    $strHienThi1 = 'checked="checked"';
	$strHienThi0 = '';
	if($arrayData["hien_thi"]==0 && $mode!="Add"){
		$strHienThi1 = '';
		$strHienThi0 = 'checked="checked"';
	}
	include_once(DIR_MODEL."md_tintuc.class.php");
	$objModelContent = new MD_Tintuc($db);

?>

<script language=javascript>

function validateForm() {
	if(document.f.ten_doi_tac.value==""){
		alert("Tiêu đề baner quảng cáo không được rỗng");
		document.f.ten_doi_tac.focus();
		return false;
	}
   if(document.f.thu_tu.value==""){
		alert("Thứ tự sắp xếp không được rỗng");
		document.f.thu_tu.focus();
		return false;
	}
   /*if (document.f.ngay_dang.value=="") {
		alert("Ngày đăng không được rỗng");
		document.f.ngay_dang.focus();
		return false; 
	}
	if (document.f.ngay_het_han.value=="") {
		alert("Ngày hết hạn không được rỗng");
		document.f.ngay_het_han.focus();
		return false; 
	}*/
	 document.f.userfile.style.backgroundColor='white';

   if (document.f.userfile.value.length>0) {
	    var filename = document.f.userfile.value;
	    var dotpos;
	    filename = filename.substring(filename.lastIndexOf("\\")+1,filename.length);
	    dotpos=filename.lastIndexOf('.');
	    ext=filename.substr(dotpos+1,3);
	    ext=ext.toLowerCase();
	    fname=filename.substr(0,dotpos);

	    if(dotpos==-1||dotpos==0){
		    alert("Tên ảnh sai rồi, xin hãy sửa lại.");
		    return false;
	    }

	    if (ext!=""){
		    if ((ext!="gif") && (ext!="jpg") && (ext!="png")  && (ext!="bmp")){
			    alert("Chỉ chấp nhận các file ảnh có định dạng mở rộng là .GIF, .JPG, .PNG. Xin hãy sửa lại.");
			    return false;
		    }
        }
    }
	return true;
}

function Focus(){
	document.f.ten_doi_tac.focus();
}

function showImage(){
	document.f.image.src = document.f.userfile.value;
}
function btnClearImgOnclick(){
	if (document.f.userfile.value != ""){
		if (confirm("Bạn có muốn xóa ảnh không?")){
			document.f.image.src = "";
			//document.f.chu_thich_anh.value = "";
			document.getElementById("fn").value='';
			document.getElementById("fileIDSpan").innerHTML=
					"<input name=\"userfile\" type=\"file\" id=\"fn\"  size=\"100\" value=\"\" onChange=\" showImage();\"/>";
		}
	}
}


function confirmDelete() 
{ 
	var msg = "Bạn có muốn xóa ảnh không?";       
	if ( confirm(msg) ) 
	{         
		return true;      
	} 
	return false;
}   
 

</script>
<link rel="stylesheet" href="../images/calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
	<SCRIPT type="text/javascript" src="../images/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>
			<?= CM_showError() ?>
<body onLoad="Focus();">
<table border="1" width="100%" align="center" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
<tbody>
<form enctype="multipart/form-data" action="<?=$ulr?>" method="post" name="f" onSubmit="return validateForm();">
<input type="hidden" name="id" value="<?=htmlspecialchars($arrayData["id"])?>" />
<input type="hidden" name="fqa" value="<?=htmlspecialchars($arrayData["fqa"])?>" />
				<tr>
				  <td colspan="2" bgcolor="#FFE59F" align="center"  class=bk12-140 ><font size="3"><strong><?=$strLabel;?></strong></font>
				  </td>
			  </tr>
				<tr>
			  		<td  width="19%" bgcolor="#FFE59F"  class=bk12-140 ><font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Tiêu đề: </font><span style="color:#FF0000;">*</span></td>
					<td colspan="2" width="81%">
			  			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
			  			<input name="ten_doi_tac" type="text" value="<?=htmlspecialchars($arrayData["ten_doi_tac"])?>" size="50" maxlength="100" /> 
			  			</font>
			  		</td>
				</tr>
				<tr>
					<td width="20%" bgcolor="#FFE59F"  class=bk12-140 >
					<font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Ảnh</font></td>

					<td height="16" align="left" >
							<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
						<img id="image" width="460" src="../images/images_upload/img_quang_cao/<?=$arrayData["anh_dai_dien"]?>" ></font>
					</td>			
				</tr>
				 <tr>
				<td  width="20%" bgcolor="#FFE59F"  class=bk12-140>
				<font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Tên ảnh: (kích thước ảnh: 760x225)</font>
				</td>
				<td>
					<?
						if($mode=="Edit"){
					?>
							<font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?=htmlspecialchars($arrayData["anh_dai_dien"])?>
							</font>	<br>
					<?	
						}else{}
					?>
					<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
						<span id="fileIDSpan"><input name="userfile" type="file" id="fn"  size="60" 
						value="<?=htmlspecialchars($arrayData["anh_dai_dien"])?>" onChange=" showImage();"/></span>
				   </font>	
				  
				</td>
					
	
			  
			</tr>
				<tr>
			  		<td  width="19%" bgcolor="#FFE59F"  class=bk12-140 ><font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Link: </font></td>
					<td colspan="2" width="81%">
						<select name="link" style="WIDTH: 200px">
			  			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
						<?
						$arrayDataContent = $objModelContent -> getByWhere("*","","ngay_tao desc");
						if(!empty($arrayDataContent)){
							foreach ($arrayDataContent as $rowContent){
								$titleContent=$rowContent["tieu_de"];
								$idContent=$rowContent["id"];
								if($idContent==$arrayData['idlink']){
								echo"<option value=$idContent selected>$titleContent</option>";
								}else{
									echo"<option value=$idContent>$titleContent</option>";
								}
								
							}//end foreach
						}
						unset($arrayDataContent);
						?>
			  			</font>
						</select>
			  		</td>
				</tr>
				 <tr>
				  <td  bgcolor="#FFE59F"  ><font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Hi&#7875;n th&#7883;:</font></td>
				  <td ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">
				 
				  </span>
					  <label>
					  <input name="hien_thi" type="radio" value="1" <?=$strHienThi1?> />
		C&oacute;</label>
					  <label>
					  <input name="hien_thi" type="radio" value="0" <?=$strHienThi0 ?> />
		Kh&ocirc;ng</label>
				  </font> </td>
				</tr>
				
				<tr>
		 <td bgcolor="#FFE59F"  class=bk12-140> <font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Th&#7913; t&#7921; sắp xếp</font><span style="color:#FF0000;">*</span></td>
		  <td  align="left">
			<input name="thu_tu" type="text" id="thu_tu" value="<?=htmlspecialchars($arrayData["thu_tu"])?>" size="4" maxlength="4" />
		 </td>
	    </tr>
        <tr>
        	<td bgcolor="#FFE59F"  class=bk12-140> <font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Mô tả</font><span style="color:#FF0000;">*</span></td>
            <td  align="left"><?php $sBasePath = $_SERVER['PHP_SELF'] ;

        // Lay ve thu muc goc cho den _sample.
        $sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "run" ) ) ;
        //echo "sBasePath = $sBasePath";
        $sBasePath = $sBasePath."fckeditor/";
        $oFCKeditor = new FCKeditor('ghi_chu') ;
        $oFCKeditor->BasePath    = $sBasePath ;
        $oFCKeditor->Width        = '100%' ;
        $oFCKeditor->Height        = '200' ;
        $oFCKeditor->Value       = $arrayData["ghi_chu"];
        $oFCKeditor->Create() ;?></td>
        </tr>
		<?
		/*<tr>
		 <td bgcolor="#FFE59F"  class=bk12-140><font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Ngày đăng</font></td>
		  <td align="left">
		  <input type="text" value="<?=htmlspecialchars($arrayData["ngay_dang"])?>" readonly name="publish_up"><input type="button" value="Cal" onclick="displayCalendar(document.forms[0].publish_up,'yyyy-mm-dd',this)">
		 </td>
	    </tr>
		<tr>
		 <td bgcolor="#FFE59F"  class=bk12-140><font color="#000099" size="2" face="Verdana, Arial, Helvetica, sans-serif">Ngày hết hạn</font></td>
		  <td align="left">
			<input type="text" value="<?=htmlspecialchars($arrayData["ngay_het_han"])?>" readonly name="publish_down"><input type="button" value="Cal" onclick="displayCalendar(document.forms[0].publish_down,'yyyy-mm-dd',this)">
		  </td>
	    </tr>
		*/
		?>

				<script language = 'JavaScript' >
				function backToList(){
					location = '<?="?".MODUL."=quangcao&".ACTION."="."List"?>';
					return;
				}
				</script>
				<tr>
					<td colspan="2" align="center">
						<input name="Reset" type="reset" value=" Nhập lại " />
						<input name="Submit" type="submit" value="<?=$strButtonLabel?>" />
						<input type="button" name="back" value="Trở lại"
						onClick="javascript: return backToList();">
					</td>
				</tr>
</form>
</tbody>
</table>
</body>

<?php
}
?>
